{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 为什么学习pandas\n",
    "- numpy已经可以帮助我们进行数据的处理了，那么学习pandas的目的是什么呢？\n",
    "    - numpy能够帮助我们处理的是数值型的数据，当然在数据分析中除了数值型的数据还有好多其他类型的数据（字符串，时间序列），那么pandas就可以帮我们很好的处理除了数值型的其他数据！"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 什么是pandas？\n",
    "- 首先先来认识pandas中的两个常用的类\n",
    "    - Series\n",
    "    - DataFrame"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Series\n",
    "- Series是一种类似与一维数组的对象，由下面两个部分组成：\n",
    "    - values：一组数据（ndarray类型）\n",
    "    - index：相关的数据索引标签"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Series的创建\n",
    "    - 由列表或numpy数组创建\n",
    "    - 由字典创建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from pandas import Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1\n",
       "1    2\n",
       "2    3\n",
       "3    4\n",
       "dtype: int64"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.array([1,2,4,7])\n",
    "\n",
    "#创建Series的方式,是一个类,可以通过类名()来实例化对象\n",
    "\n",
    "s = Series()\n",
    "#直接放入一维数组\n",
    "s = Series(data = [1,2,3,4]) #并不统一类型\n",
    "\n",
    "#标准list的类型是不限制,默认可以为object(类型有特定值)\n",
    "\n",
    "\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    50\n",
       "1    68\n",
       "2    68\n",
       "dtype: uint8"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#可以通过numpy创建的一维数组\n",
    "s1 = Series(data=np.random.randint(0,100,size=(3,),dtype = 'uint8'))\n",
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "name        Alice\n",
       "age            18\n",
       "id      123456789\n",
       "dtype: object"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data= {'a':1,'b':2,'c':3}\n",
    "data = {'name':\"Alice\",'age':18,'id':123456789}\n",
    "\n",
    "s = Series(data =data)\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a       1\n",
       "b       2\n",
       "c       3\n",
       "d    four\n",
       "dtype: object"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#index用来指定显示索引\n",
    "s = Series(data=[1,2,3,'four'],index=['a','b','c','d'])\n",
    "#一旦指定index,就必须匹配,直接覆盖原本index\n",
    "s"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 为什么需要有显示索引\n",
    "> 显示索引可以增强Series的可读性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "name      小明\n",
       "age       19\n",
       "id      1001\n",
       "dtype: object"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic = {\n",
    "    '语文':100,\n",
    "    '数学':99,\n",
    "    '理综':250\n",
    "}\n",
    "\n",
    "student = {'name':\"小明\",'age':19,'id':1001}\n",
    "s = Series(data=student)\n",
    "s"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Series的索引和切片\n",
    "- 基本与numpy一致,但增加了特殊index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'a'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "File \u001b[1;32md:\\Anaconda3\\Lib\\site-packages\\pandas\\core\\indexes\\base.py:3805\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   3804\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m-> 3805\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_engine\u001b[38;5;241m.\u001b[39mget_loc(casted_key)\n\u001b[0;32m   3806\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n",
      "File \u001b[1;32mindex.pyx:167\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mindex.pyx:196\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mpandas\\\\_libs\\\\hashtable_class_helper.pxi:7081\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mpandas\\\\_libs\\\\hashtable_class_helper.pxi:7089\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: 'a'",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[7], line 7\u001b[0m\n\u001b[0;32m      4\u001b[0m s1[[\u001b[38;5;241m0\u001b[39m,\u001b[38;5;241m2\u001b[39m]]\n\u001b[0;32m      6\u001b[0m \u001b[38;5;66;03m#没有位置索引,通过index\u001b[39;00m\n\u001b[1;32m----> 7\u001b[0m s[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124ma\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[0;32m      8\u001b[0m s\u001b[38;5;241m.\u001b[39ma\n\u001b[0;32m      9\u001b[0m s[::\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m]\n",
      "File \u001b[1;32md:\\Anaconda3\\Lib\\site-packages\\pandas\\core\\series.py:1121\u001b[0m, in \u001b[0;36mSeries.__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   1118\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_values[key]\n\u001b[0;32m   1120\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m key_is_scalar:\n\u001b[1;32m-> 1121\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_get_value(key)\n\u001b[0;32m   1123\u001b[0m \u001b[38;5;66;03m# Convert generator to list before going through hashable part\u001b[39;00m\n\u001b[0;32m   1124\u001b[0m \u001b[38;5;66;03m# (We will iterate through the generator there to check for slices)\u001b[39;00m\n\u001b[0;32m   1125\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_iterator(key):\n",
      "File \u001b[1;32md:\\Anaconda3\\Lib\\site-packages\\pandas\\core\\series.py:1237\u001b[0m, in \u001b[0;36mSeries._get_value\u001b[1;34m(self, label, takeable)\u001b[0m\n\u001b[0;32m   1234\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_values[label]\n\u001b[0;32m   1236\u001b[0m \u001b[38;5;66;03m# Similar to Index.get_value, but we do not fall back to positional\u001b[39;00m\n\u001b[1;32m-> 1237\u001b[0m loc \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mindex\u001b[38;5;241m.\u001b[39mget_loc(label)\n\u001b[0;32m   1239\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_integer(loc):\n\u001b[0;32m   1240\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_values[loc]\n",
      "File \u001b[1;32md:\\Anaconda3\\Lib\\site-packages\\pandas\\core\\indexes\\base.py:3812\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   3807\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(casted_key, \u001b[38;5;28mslice\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m (\n\u001b[0;32m   3808\u001b[0m         \u001b[38;5;28misinstance\u001b[39m(casted_key, abc\u001b[38;5;241m.\u001b[39mIterable)\n\u001b[0;32m   3809\u001b[0m         \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28many\u001b[39m(\u001b[38;5;28misinstance\u001b[39m(x, \u001b[38;5;28mslice\u001b[39m) \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m casted_key)\n\u001b[0;32m   3810\u001b[0m     ):\n\u001b[0;32m   3811\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m InvalidIndexError(key)\n\u001b[1;32m-> 3812\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01merr\u001b[39;00m\n\u001b[0;32m   3813\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[0;32m   3814\u001b[0m     \u001b[38;5;66;03m# If we have a listlike key, _check_indexing_error will raise\u001b[39;00m\n\u001b[0;32m   3815\u001b[0m     \u001b[38;5;66;03m#  InvalidIndexError. Otherwise we fall through and re-raise\u001b[39;00m\n\u001b[0;32m   3816\u001b[0m     \u001b[38;5;66;03m#  the TypeError.\u001b[39;00m\n\u001b[0;32m   3817\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_check_indexing_error(key)\n",
      "\u001b[1;31mKeyError\u001b[0m: 'a'"
     ]
    }
   ],
   "source": [
    "#位置索引(默认就是用的index,前提是没有被覆盖)\n",
    "s1[0]\n",
    "s1[::-1]\n",
    "s1[[0,2]]\n",
    "\n",
    "#没有位置索引,通过index\n",
    "s['a']\n",
    "s.a\n",
    "s[::-1]\n",
    "s['c':'a':-1]\n",
    "#s['a':-1] #位置索引和index索引不能混合使用\n",
    "\n",
    "#索引被覆盖了,原来的位置索引不能直接用\n",
    "s.iloc[0] #使用iloc可以获取位置索引\n",
    "s.iloc[::-1]\n",
    "s.iloc[[0,2]]\n",
    "\n",
    "#loc是取位置索引\n",
    "s.loc['a']\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.age"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Series的常用属性\n",
    "    - shape\n",
    "    - size\n",
    "    - index\n",
    "    - values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('O')"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.shape\n",
    "s.size\n",
    "s.index #返回索引\n",
    "s.values #返回 值\n",
    "s.dtype #元素的类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('O')"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = Series(data=[1,2,3,'four'],index=['a','b','c','d'])\n",
    "s.dtype #数据类型O表示的是Object（字符串类型）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Series的常用方法\n",
    "    - head(),tail()\n",
    "    - unique()\n",
    "    - isnull(),notnull()\n",
    "    - add() sub() mul() div() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    81\n",
       "1    89\n",
       "2    95\n",
       "dtype: int32"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = Series(data=np.random.randint(60,100,size=(10,)))\n",
    "s.head(3) #显示前n个数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7    80\n",
       "8    85\n",
       "9    78\n",
       "dtype: int32"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.tail(3) #显示后n个元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([81, 89, 95, 78, 66, 86, 88, 80, 85])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.unique() #去重"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    False\n",
       "1    False\n",
       "2     True\n",
       "3    False\n",
       "4    False\n",
       "dtype: bool"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Series([1,2,None,3,4]).isnull() #用于判断每一个元素是否为空，为空返回True，否则返回False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    True\n",
       "1    True\n",
       "2    True\n",
       "3    True\n",
       "4    True\n",
       "5    True\n",
       "6    True\n",
       "7    True\n",
       "8    True\n",
       "9    True\n",
       "dtype: bool"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.notnull()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Series的算术运算\n",
    "    - 法则：索引一致的元素进行算数运算否则补空"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    2.0\n",
       "b    NaN\n",
       "c    6.0\n",
       "d    NaN\n",
       "dtype: float64"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = Series(data=[1,2,3],index=['a','b','c'])\n",
    "s2 = Series(data=[1,2,3],index=['a','d','c'])\n",
    "s = s1 + s2\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    False\n",
       "b     True\n",
       "c    False\n",
       "d     True\n",
       "dtype: bool"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.isnull()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### DataFrame\n",
    "- DataFrame是一个【表格型】的数据结构。DataFrame由按一定顺序排列的多列数据组成。设计初衷是将Series的使用场景从一维拓展到多维。DataFrame既有行索引，也有列索引。\n",
    "    - 行索引：index\n",
    "    - 列索引：columns\n",
    "    - 值：values"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- DataFrame的创建\n",
    "    - ndarray创建\n",
    "    - 字典创建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>222</th>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>333</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     a  b  c\n",
       "111  1  6  4\n",
       "222  1  9  6\n",
       "333  1  2  8"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pandas import DataFrame\n",
    "\n",
    "\n",
    "#二维的列表\n",
    "pd.DataFrame([[1,2,3],[4,5,6],[7,8,9]],columns=['a','b','c'],index = [\"A\",\"B\",\"C\"])\n",
    "\n",
    "#numpy生成二维数组\n",
    "pd.DataFrame(np.random.randint(1,10,size = (3,3)),columns=['a','b','c'],index=['111','222','333'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   0  1  2\n",
       "0  1  2  3\n",
       "1  4  5  6"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = DataFrame(data=[[1,2,3],[4,5,6]])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>45</td>\n",
       "      <td>16</td>\n",
       "      <td>47</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>51</td>\n",
       "      <td>41</td>\n",
       "      <td>22</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>69</td>\n",
       "      <td>77</td>\n",
       "      <td>36</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>63</td>\n",
       "      <td>77</td>\n",
       "      <td>24</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>79</td>\n",
       "      <td>69</td>\n",
       "      <td>33</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>89</td>\n",
       "      <td>18</td>\n",
       "      <td>44</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    0   1   2   3\n",
       "0  45  16  47   5\n",
       "1  51  41  22  99\n",
       "2  69  77  36  38\n",
       "3  63  77  24  64\n",
       "4  79  69  33  64\n",
       "5  89  18  44  28"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = DataFrame(data=np.random.randint(0,100,size=(6,4)))\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "原本的数据可以直接转化\n",
    "\n",
    "如果字典,之前的形式,一个字典就是一个对象{name:小明,age:19}\n",
    "嵌套,对dataFrame的格式不兼容\n",
    "对象的格式是一致的  name: aaa  bbbb  cccc\n",
    "                    age  18    19    20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>salary</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>zhangsan</td>\n",
       "      <td>1000</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>lisi</td>\n",
       "      <td>2000</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>wanglaowu</td>\n",
       "      <td>3000</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        name  salary  age\n",
       "a   zhangsan    1000   12\n",
       "b       lisi    2000   17\n",
       "c  wanglaowu    3000   19"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "data = {'id':1001,'name':'Alice','gender':'女'}\n",
    "s = pd.Series(data)  #此时,key作为series的index\n",
    "\n",
    "\n",
    "dic = {\n",
    "    'name':['zhangsan','lisi','wanglaowu'],\n",
    "    'salary':[1000,2000,3000],\n",
    "    'age':(12,17,19)\n",
    "}\n",
    "df = DataFrame(data=dic,index=['a','b','c'])\n",
    "\n",
    "#关键值是列名 columns\n",
    "df['name']\n",
    "\n",
    "df\n",
    "\n",
    "# df.set_index('name')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- DataFrame的属性\n",
    "    - values、columns、index、shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3, 3)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.values\n",
    "df.columns\n",
    "df.index #生成的range(默认情况下)\n",
    "df.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "============================================\n",
    "\n",
    "练习4：\n",
    "\n",
    "根据以下考试成绩表，创建一个DataFrame，命名为df：\n",
    "```\n",
    "    张三  李四  \n",
    "语文 150  0\n",
    "数学 150  0\n",
    "英语 150  0\n",
    "理综 300  0\n",
    "```\n",
    "\n",
    "============================================"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>张三</th>\n",
       "      <td>100</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>李四</th>\n",
       "      <td>20</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>王五</th>\n",
       "      <td>60</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>赵六</th>\n",
       "      <td>70</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     语文  数学\n",
       "张三  100  67\n",
       "李四   20  89\n",
       "王五   60  90\n",
       "赵六   70  12"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic = {\n",
    "    '张三':[150,150,150,150],\n",
    "    '李四':[0,0,0,0]\n",
    "}\n",
    "\n",
    "dic1 = {'语文':[100,20,60,70],\n",
    "       '数学':[67,89,90,12]}\n",
    "df1 = DataFrame(data=dic1,index = ['张三','李四','王五','赵六'])\n",
    "df = DataFrame(data=dic,index=['语文','数学','英语','理综'])\n",
    "df1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- DataFrame索引操作\n",
    "    - 对行进行索引\n",
    "    - 队列进行索引\n",
    "    - 对元素进行索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>李四</th>\n",
       "      <th>王五</th>\n",
       "      <th>赵六</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "      <td>12</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "      <td>89</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "      <td>20</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     张三  李四  王五  赵六\n",
       "语文  150   0  12  45\n",
       "数学  150   0  14  67\n",
       "英语  150   0  89  89\n",
       "理综  150   0  20  60"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "\n",
    "\n",
    "dic = {\n",
    "    '张三':[150,150,150,150],\n",
    "    '李四':[0,0,0,0],\n",
    "    '王五':[12,14,89,20],\n",
    "    '赵六':[45,67,89,60],\n",
    "}\n",
    "\n",
    "\n",
    "df = DataFrame(data=dic,index=['语文','数学','英语','理综'])\n",
    "\n",
    "\n",
    "# df = DataFrame(data=np.random.randint(60,100,size=(8,4)))\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "语文    150\n",
       "数学    150\n",
       "英语    150\n",
       "理综    150\n",
       "Name: 张三, dtype: int64"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#取一个维度\n",
    "df['张三'] #取单列，如果df有显示的索引，通过索引机制去行或者列的时候只可以使用显示索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "150"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#取单一值\n",
    "#只要取出维度为1的数据,就会转化为Serise\n",
    "df['张三'][\"理综\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>赵六</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>150</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>150</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>150</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>150</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     张三  赵六\n",
       "语文  150  45\n",
       "数学  150  67\n",
       "英语  150  89\n",
       "理综  150  60"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['张三','赵六']] #取多列"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- iloc:\n",
    "    - 通过隐式索引取行\n",
    "- loc:\n",
    "    - 通过显示索引取行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>salary</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>stu1</th>\n",
       "      <td>zhangsan</td>\n",
       "      <td>1000</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stu2</th>\n",
       "      <td>lisi</td>\n",
       "      <td>2000</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stu3</th>\n",
       "      <td>wanglaowu</td>\n",
       "      <td>3000</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           name  salary  age\n",
       "stu1   zhangsan    1000   12\n",
       "stu2       lisi    2000   17\n",
       "stu3  wanglaowu    3000   19"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic = {\n",
    "    'name':['zhangsan','lisi','wanglaowu'],\n",
    "    'salary':[1000,2000,3000],\n",
    "    'age':(12,17,19)\n",
    "}\n",
    "df = DataFrame(data=dic,index=['stu1','stu2','stu3'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "name      zhangsan\n",
       "salary        1000\n",
       "age             12\n",
       "Name: stu1, dtype: object"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# arr[行,列]\n",
    "\n",
    "#取单行\n",
    "df.loc['stu1'] #必须是index值,而不是位置索引(位置索引使用iloc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "name      wanglaowu\n",
       "salary         3000\n",
       "age              19\n",
       "Name: stu3, dtype: object"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[2]#位置索引(位置索引使用iloc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>salary</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>stu1</th>\n",
       "      <td>zhangsan</td>\n",
       "      <td>1000</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stu3</th>\n",
       "      <td>wanglaowu</td>\n",
       "      <td>3000</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           name  salary  age\n",
       "stu1   zhangsan    1000   12\n",
       "stu3  wanglaowu    3000   19"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#取多行\n",
    "df.iloc[[0,1]]\n",
    "df.iloc[[True,False,True]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>stu1</th>\n",
       "      <td>zhangsan</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stu2</th>\n",
       "      <td>lisi</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stu3</th>\n",
       "      <td>wanglaowu</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           name  age\n",
       "stu1   zhangsan   12\n",
       "stu2       lisi   17\n",
       "stu3  wanglaowu   19"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#只取某一列,不需要loc,直接获取索引即可\n",
    "\n",
    "#无法灵活的限制位置\n",
    "df['name']\n",
    "\n",
    "df[['name','age']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>stu1</th>\n",
       "      <td>zhangsan</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stu2</th>\n",
       "      <td>lisi</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stu3</th>\n",
       "      <td>wanglaowu</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           name  age\n",
       "stu1   zhangsan   12\n",
       "stu2       lisi   17\n",
       "stu3  wanglaowu   19"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[0,0]\n",
    "\n",
    "#取一整列\n",
    "df.iloc[:,0]\n",
    "\n",
    "#第1,2行,的name salary\n",
    "df.iloc[:2,:2]\n",
    "\n",
    "df.loc[:,['name','salary']]\n",
    "\n",
    "#所有人的name 和age\n",
    "df.loc[:,['name','age']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#取单个元素\n",
    "df.iloc[0,2]\n",
    "# df.loc[0,'a']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "#取多个元素\n",
    "# df.iloc[[1,3,5],2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- DataFrame的切片操作\n",
    "    - 对行进行切片\n",
    "    - 对列进行切片\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>salary</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>stu1</th>\n",
       "      <td>zhangsan</td>\n",
       "      <td>1000</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stu2</th>\n",
       "      <td>lisi</td>\n",
       "      <td>2000</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          name  salary  age\n",
       "stu1  zhangsan    1000   12\n",
       "stu2      lisi    2000   17"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#切行\n",
    "df[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>stu1</th>\n",
       "      <td>zhangsan</td>\n",
       "      <td>1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stu2</th>\n",
       "      <td>lisi</td>\n",
       "      <td>2000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>stu3</th>\n",
       "      <td>wanglaowu</td>\n",
       "      <td>3000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           name  salary\n",
       "stu1   zhangsan    1000\n",
       "stu2       lisi    2000\n",
       "stu3  wanglaowu    3000"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#切列\n",
    "df.iloc[:,0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "salary    2000\n",
       "age         17\n",
       "Name: lisi, dtype: int64"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic = {\n",
    "    'name':['zhangsan','lisi','wanglaowu'],\n",
    "    'salary':[1000,2000,3000],\n",
    "    'age':(12,17,19)\n",
    "}\n",
    "df = DataFrame(data=dic,index=['stu1','stu2','stu3'])\n",
    "df\n",
    "\n",
    "\n",
    "df.set_index('name',inplace=True) #将某一列作为index\n",
    "\n",
    "df.loc['lisi']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- df索引和切片操作\n",
    "    - 索引：\n",
    "        - df[col]:取列\n",
    "        - df.loc[index]:取行\n",
    "        - df.iloc[index,col]:取元素\n",
    "    - 切片：\n",
    "        - df[index1:index3]:切行\n",
    "        - df.iloc[:,col1:col3]:切列"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- DataFrame的运算\n",
    "    - 同Series"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "============================================\n",
    "\n",
    "练习：\n",
    "\n",
    "1. 假设ddd是期中考试成绩，ddd2是期末考试成绩，请自由创建ddd2，并将其与ddd相加，求期中期末平均值。\n",
    "\n",
    "2. 假设张三期中考试数学被发现作弊，要记为0分，如何实现？\n",
    "\n",
    "3. 李四因为举报张三作弊立功，期中考试所有科目加100分，如何实现？\n",
    "\n",
    "4. 后来老师发现有一道题出错了，为了安抚学生情绪，给每位学生每个科目都加10分，如何实现？\n",
    "\n",
    "============================================"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "dic = {\n",
    "    '张三':[150,150,150,150],\n",
    "    '李四':[0,0,0,0]\n",
    "}\n",
    "df = DataFrame(data=dic,index=['语文','数学','英语','理综'])\n",
    "qizhong = df\n",
    "qimo = df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>李四</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>150.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>150.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>150.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>150.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       张三   李四\n",
       "语文  150.0  0.0\n",
       "数学  150.0  0.0\n",
       "英语  150.0  0.0\n",
       "理综  150.0  0.0"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(qizhong + qizhong) / 2 #期中期末的平均值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>李四</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     张三  李四\n",
       "语文  150   0\n",
       "数学    0   0\n",
       "英语  150   0\n",
       "理综  150   0"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qizhong.loc['数学','张三'] = 0\n",
    "qizhong #将张三的数学成绩修改为0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>李四</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>150</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>0</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>150</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>150</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     张三   李四\n",
       "语文  150  100\n",
       "数学    0  100\n",
       "英语  150  100\n",
       "理综  150  100"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将李四的所有成绩+100\n",
    "qizhong['李四']+=100\n",
    "qizhong"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>李四</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>160</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>10</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>160</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>160</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     张三   李四\n",
       "语文  160  110\n",
       "数学   10  110\n",
       "英语  160  110\n",
       "理综  160  110"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qizhong += 10\n",
    "qizhong #将所有学生的成绩+10"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 时间数据类型的转换\n",
    "    - pd.to_datetime(col)\n",
    "- 将某一列设置为行索引\n",
    "    - df.set_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>temp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2010-10-10</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2011-11-20</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2020-01-10</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         time  temp\n",
       "0  2010-10-10    33\n",
       "1  2011-11-20    31\n",
       "2  2020-01-10    30"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic = {\n",
    "    'time':['2010-10-10','2011-11-20','2020-01-10'],\n",
    "    'temp':[33,31,30]\n",
    "}\n",
    "df = DataFrame(data=dic)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('O')"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#查看time列的类型\n",
    "df['time'].dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(df[\"time\"][0]) #是str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('2024-09-23 15:26:53.111608')"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将time列的数据类型转换成时间序列类型\n",
    "df['time'] = pd.to_datetime(df['time'])\n",
    "\n",
    "\n",
    "pd.to_datetime(df['time'])\n",
    "\n",
    "df.iloc[0,0].today()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    10\n",
       "1    20\n",
       "2    10\n",
       "Name: time, dtype: int32"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "df['time']\n",
    "df['time'].dt.day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "#将time列作为源数据的行索引\n",
    "\n",
    "#有没有覆盖原来的index\n",
    "df.set_index('time',inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>temp</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2010-10-10</th>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-11-20</th>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-10</th>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            temp\n",
       "time            \n",
       "2010-10-10    33\n",
       "2011-11-20    31\n",
       "2020-01-10    30"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 对DataFrame的操作\n",
    "\n",
    "### 列(直接)\n",
    "1. 增\n",
    "2. 删\n",
    "3. 查\n",
    "直接通过列名获取\n",
    "4. 改\n",
    "\n",
    "### 行(通过函数或方法)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>李四</th>\n",
       "      <th>王五</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>语文</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数学</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>英语</th>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>理综</th>\n",
       "      <td>_40</td>\n",
       "      <td>0</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     张三  李四   王五\n",
       "语文    1   0   50\n",
       "数学    2   0  100\n",
       "英语    3   0   80\n",
       "理综  _40   0   70"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic = {\n",
    "    '张三':[150,150,150,150],\n",
    "    '李四':[0,0,0,0]\n",
    "}\n",
    "df = DataFrame(data=dic,index=['语文','数学','英语','理综'])\n",
    "\n",
    "#查\n",
    "df['张三']\n",
    "\n",
    "#改\n",
    "df['张三'] = ['1','2','3','_40']\n",
    "\n",
    "w5 = pd.Series([100,50,80,70],index = ['数学','语文','英语','理综'])\n",
    "#增加,直接对想增加的列名直接赋值即可\n",
    "df['王五'] = w5\n",
    "\n",
    "# #删除\n",
    "# df.pop('李四')\n",
    "\n",
    "# del df['张三']\n",
    "\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': '小明', 'age': 19}"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict1 = {'name':\"小明\"}\n",
    "\n",
    "dict1['age'] = 19\n",
    "dict1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>张三</th>\n",
       "      <th>李四</th>\n",
       "      <th>王五</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    张三  李四   王五\n",
       "0  150   0  NaN\n",
       "1  150   0  NaN\n",
       "2  150   0  NaN\n",
       "3  150   0  NaN\n",
       "4  150   0  1.0\n",
       "5  150   0  2.0\n",
       "6    1   2  4.0\n",
       "7    1   2  4.0"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic = {\n",
    "    '张三':[150,150,150,150],\n",
    "    '李四':[0,0,0,0]\n",
    "}\n",
    "df = DataFrame(data=dic,index=['语文','数学','英语','理综'])\n",
    "\n",
    "#行操作\n",
    "#增\n",
    "dic = {\n",
    "    '张三':[150,150],\n",
    "    '李四':[0,0],\n",
    "    '王五':[1,2]\n",
    "}\n",
    "df1 = DataFrame(data=dic,index =['体育','美术'])\n",
    "\n",
    "\n",
    "#增加一个表(增加多个值采用append)\n",
    "\n",
    "df = df._append(df1,ignore_index=False) #不对原来的表进行操作的,而是返回一个新表\n",
    "\n",
    "#增加一个新行(直接用索引好一些)\n",
    "s1 = Series([1,2,4],index= ['张三','李四','王五'])  \n",
    "\n",
    "df.loc['meis'] = s1\n",
    "\n",
    "\n",
    "df._append(s1,ignore_index = True)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>gender</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Alice</td>\n",
       "      <td>16</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Bob</td>\n",
       "      <td>17</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Candy</td>\n",
       "      <td>18</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>David</td>\n",
       "      <td>19</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Eric</td>\n",
       "      <td>10</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    name  age gender\n",
       "0  Alice   16      女\n",
       "1    Bob   17      男\n",
       "2  Candy   18      女\n",
       "3  David   19      男\n",
       "4   Eric   10      男"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {'name':['Alice','Bob','Candy','David','Eric'],\n",
    "        'age':[16,17,18,19,10],\n",
    "        'gender':['女','男','女','男','男']\n",
    "}\n",
    "df = pd.DataFrame(data=data)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1001\n",
       "1    1002\n",
       "2    1003\n",
       "3    1004\n",
       "4    1005\n",
       "Name: id, dtype: object"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#列的操作\n",
    "\n",
    "#增\n",
    "df['id'] = ['1001','1002','1003','1004','1005']\n",
    "\n",
    "#改,跟上面一致\n",
    "\n",
    "#删\n",
    "# del df['id']\n",
    "df.pop('id') #也是删除,删除的是原始数据,返回删除的内容Serise\n",
    "\n",
    "#查\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>age</th>\n",
       "      <th>gender</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Alice</td>\n",
       "      <td>16</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Bob</td>\n",
       "      <td>17</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Candy</td>\n",
       "      <td>18</td>\n",
       "      <td>女</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>David</td>\n",
       "      <td>19</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>F</td>\n",
       "      <td>28</td>\n",
       "      <td>男</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    name  age gender\n",
       "0  Alice   16      女\n",
       "1    Bob   17      男\n",
       "2  Candy   18      女\n",
       "3  David   19      男\n",
       "4      F   28      男"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#行的操作\n",
    "\n",
    "#增加\n",
    "# df.iloc[5] = ['F',28,'男']\n",
    "\n",
    "new_line = pd.Series(['F',28,'男'],index=['name','age','gender'])\n",
    "\n",
    "df = df._append(new_line,ignore_index=True) #返回一个新的表格,对原本的数据不进行更改\n",
    "#ignore_index必须追加\n",
    "\n",
    "#删除,返回一个新的表格,对原来的值没有影响\n",
    "df = df.drop(5)\n",
    "\n",
    "#改,loc是对原本值更改的\n",
    "df.iloc[4] = ['F',28,'男']\n",
    "\n",
    "df\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>购药时间</th>\n",
       "      <th>社保卡号</th>\n",
       "      <th>商品编码</th>\n",
       "      <th>商品名称</th>\n",
       "      <th>销售数量</th>\n",
       "      <th>应收金额</th>\n",
       "      <th>实收金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-01 星期五</td>\n",
       "      <td>1.616528e+06</td>\n",
       "      <td>236701.0</td>\n",
       "      <td>强力VC银翘片</td>\n",
       "      <td>6.0</td>\n",
       "      <td>82.8</td>\n",
       "      <td>69.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-01-01 星期五</td>\n",
       "      <td>1.014705e+08</td>\n",
       "      <td>236709.0</td>\n",
       "      <td>心痛定</td>\n",
       "      <td>4.0</td>\n",
       "      <td>179.2</td>\n",
       "      <td>159.20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-01-01 星期五</td>\n",
       "      <td>1.007261e+10</td>\n",
       "      <td>2367011.0</td>\n",
       "      <td>开博通</td>\n",
       "      <td>1.0</td>\n",
       "      <td>28.0</td>\n",
       "      <td>25.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-01-01 星期五</td>\n",
       "      <td>1.007460e+10</td>\n",
       "      <td>2367011.0</td>\n",
       "      <td>开博通</td>\n",
       "      <td>5.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>125.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-01-01 星期五</td>\n",
       "      <td>1.174343e+07</td>\n",
       "      <td>861405.0</td>\n",
       "      <td>苯磺酸氨氯地平片(络活喜)</td>\n",
       "      <td>1.0</td>\n",
       "      <td>34.5</td>\n",
       "      <td>31.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6573</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1.177863e+07</td>\n",
       "      <td>2367011.0</td>\n",
       "      <td>高特灵</td>\n",
       "      <td>10.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>56.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6574</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6575</th>\n",
       "      <td>2018-04-27 星期三</td>\n",
       "      <td>1.008787e+10</td>\n",
       "      <td>2367011.0</td>\n",
       "      <td>高特灵</td>\n",
       "      <td>2.0</td>\n",
       "      <td>11.2</td>\n",
       "      <td>9.86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6576</th>\n",
       "      <td>2018-04-27 星期三</td>\n",
       "      <td>1.340663e+07</td>\n",
       "      <td>2367011.0</td>\n",
       "      <td>高特灵</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.6</td>\n",
       "      <td>5.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6577</th>\n",
       "      <td>2018-04-28 星期四</td>\n",
       "      <td>1.192693e+07</td>\n",
       "      <td>2367011.0</td>\n",
       "      <td>高特灵</td>\n",
       "      <td>2.0</td>\n",
       "      <td>11.2</td>\n",
       "      <td>10.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>6578 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                购药时间          社保卡号       商品编码           商品名称  销售数量   应收金额  \\\n",
       "0     2018-01-01 星期五  1.616528e+06   236701.0        强力VC银翘片   6.0   82.8   \n",
       "1     2018-01-01 星期五  1.014705e+08   236709.0            心痛定   4.0  179.2   \n",
       "2     2018-01-01 星期五  1.007261e+10  2367011.0            开博通   1.0   28.0   \n",
       "3     2018-01-01 星期五  1.007460e+10  2367011.0            开博通   5.0  140.0   \n",
       "4     2018-01-01 星期五  1.174343e+07   861405.0  苯磺酸氨氯地平片(络活喜)   1.0   34.5   \n",
       "...              ...           ...        ...            ...   ...    ...   \n",
       "6573             NaN  1.177863e+07  2367011.0            高特灵  10.0   56.0   \n",
       "6574             NaN           NaN        NaN            NaN   NaN    NaN   \n",
       "6575  2018-04-27 星期三  1.008787e+10  2367011.0            高特灵   2.0   11.2   \n",
       "6576  2018-04-27 星期三  1.340663e+07  2367011.0            高特灵   1.0    5.6   \n",
       "6577  2018-04-28 星期四  1.192693e+07  2367011.0            高特灵   2.0   11.2   \n",
       "\n",
       "        实收金额  \n",
       "0      69.00  \n",
       "1     159.20  \n",
       "2      25.00  \n",
       "3     125.00  \n",
       "4      31.00  \n",
       "...      ...  \n",
       "6573   56.00  \n",
       "6574     NaN  \n",
       "6575    9.86  \n",
       "6576    5.00  \n",
       "6577   10.00  \n",
       "\n",
       "[6578 rows x 7 columns]"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#外部的导入和保存\n",
    "data = pd.read_excel('../resource/朝阳医院2018年销售数据.xlsx')\n",
    "\n",
    "\n",
    "# df.to_excel('../resource/test.xlsx')\n",
    "# df.to_sql()\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'**盐酸阿罗洛尔片(阿尔马尔)': [79, 232, 246, 861, 893, 1053, 1109, 1305, 1545, 1582, 2016, 2179, 2425, 2719, 2861, 3048, 3991, 4061, 4332, 4408, 5062, 5313, 5551, 5587, 5674, 5783, 5784, 5863, 5905, 5977, 6038, 6136, 6223, 6285], '**阿替洛尔片': [480, 696, 2612, 3755, 3775, 4583, 5095, 5604], 'D厄贝沙坦氢氯噻嗪片(倍悦)': [5407], 'D替格瑞洛片': [4673], 'D盐酸贝尼地平片': [4221, 6205, 6311], 'D苯磺酸氨氯地平胶囊(丽珠优可)': [3659], 'G厄贝沙坦分散片(6盒/疗程)': [584, 2511, 2544, 4219, 4337, 4423, 5584, 5585, 6112], 'G琥珀酸美托洛尔缓释片(倍他乐克)': [152, 153, 289, 315, 316, 349, 381, 458, 459, 511, 552, 553, 706, 712, 733, 787, 788, 807, 808, 816, 817, 818, 874, 946, 1078, 1116, 1125, 1156, 1157, 1188, 1189, 1190, 1244, 1258, 1312, 1313, 1314, 1379, 1451, 1452, 1540, 1572, 1599, 1609, 1707, 1708, 1709, 1753, 1795, 1871, 1971, 1972, 2021, 2118, 2173, 2178, 2197, 2230, 2285, 2286, 2304, 2305, 2344, 2362, 2363, 2394, 2395, 2431, 2480, 2481, 2482, 2540, 2568, 2637, 2638, 2660, 2742, 2747, 2773, 2794, 2814, 2839, 2911, 2982, 2983, 2999, 3000, 3124, 3125, 3176, 3428, 3429, 3430, 3431, 3443, 3702, 3782, 3810, 3912, 3913, ...], 'G硝苯地平缓释片(II)(6盒/疗程)': [869, 1082, 1596, 1843, 2365, 2661, 4754, 6513, 6538], 'G缬沙坦胶囊': [170, 291, 411, 738, 805, 1123, 1165, 1458, 1576, 1892, 1986, 2485, 2545, 2657, 2796, 2871, 3046, 3103, 3441, 3665, 3710, 3936, 4145, 4569, 5050, 5105, 5187, 5869, 5968, 5969, 6015, 6100, 6166, 6417, 6475], 'G苯磺酸氨氯地平片(6盒/疗程)': [63, 148, 310, 311, 312, 313, 457, 578, 609, 611, 638, 704, 705, 972, 999, 1077, 1126, 1127, 1187, 1242, 1378, 1410, 1462, 1634, 1704, 1794, 1969, 2020, 2114, 2391, 2392, 2456, 2510, 2547, 2665, 2666, 2741, 2748, 2866, 3040, 3041, 3122, 3669, 3910, 3966, 4396, 4420, 4618, 4637, 4643, 4667, 4700, 4733, 4834, 5064, 5165, 5236, 5238, 5317, 5348, 5353, 5376, 5578, 5610, 5637, 5737, 5939, 6082, 6287, 6390, 6506, 6560], 'KG替米沙坦片(欧美宁)(6盒/疗程)': [200, 224, 225, 230, 322, 353, 462, 554, 580, 581, 658, 708, 789, 790, 866, 975, 1080, 1193, 1260, 1396, 1610, 1614, 1636, 1722, 1798, 1821, 1822, 1825, 1916, 2025, 2141, 2288, 2306, 2307, 2396, 2483, 2640, 2641, 2702, 2706, 2721, 2812, 2868, 3001, 3042, 3099, 3432, 3704, 3784, 3854, 4045, 4210, 4335, 4613, 4642, 4859, 4919, 5016, 5170, 5192, 5350, 5489, 5530, 5558, 5581, 5614, 5795, 5796, 5910, 5964, 5985, 5986, 6035, 6087, 6164, 6261, 6508, 6536, 6563], 'KG非洛地平缓释片(易特欣)(6盒/疗程)': [64, 159, 226, 227, 513, 636, 709, 948, 1160, 1196, 1715, 1716, 1913, 1989, 2294, 2342, 2455, 2486, 2647, 2873, 2918, 2990, 3077, 3094, 3660, 4401, 4422, 4502, 4535, 4982, 5019, 5045, 5104, 5801, 5812, 5982, 6165], 'TG厄贝沙坦片': [558], 'TG盐酸贝那普利片(新亚富舒)': [1800, 2200], 'x硝苯地平缓释片(伲福达)': [15, 59, 77, 126, 127, 175, 284, 285, 342, 414, 545, 614, 629, 640, 772, 773, 774, 775, 776, 832, 833, 859, 938, 954, 1033, 1104, 1131, 1153, 1182, 1223, 1224, 1386, 1436, 1468, 1482, 1516, 1561, 1589, 1685, 1686, 1729, 1950, 1951, 2041, 2063, 2093, 2094, 2099, 2152, 2168, 2359, 2471, 2562, 2697, 2698, 2799, 2800, 2808, 2818, 3146, 3154, 3271, 3318, 3319, 3651, 3698, 3831, 3844, 3894, 3941, 4010, 4035, 4058, 4118, 4327, 4328, 4418, 4450, 4484, 4634, 4662, 4675, 4693, 4813, 4814, 4892, 4927, 4976, 5093, 5124, 5154, 5155, 5232, 5448, 5573, 5574, 5724, 5725, 5778, 5819, ...], 'x福辛普利钠片(蒙诺)': [103, 366, 598, 665, 965, 1287, 1358, 1587, 1784, 1940, 2324, 2404, 2692, 2805, 3837, 4299, 4433, 4550, 4657, 4716, 5145, 5950], 'x阿司匹林': [248, 346, 380, 1038, 1197, 1539, 1571, 1581, 1826, 2116, 2539, 2778, 2980, 3100, 3152, 3268, 3450, 3850, 4352, 4950, 5318, 5349, 5467, 5840, 6392], '三九感冒灵': [297, 417, 619, 620, 916, 1014, 1493, 1606, 1645, 1923, 1924, 4386, 5137, 6238], '卡托普利片': [20, 318, 319, 385, 409, 734, 794, 899, 905, 1397, 1577, 1714, 1974, 2073, 2097, 2119, 2427, 2428, 2429, 2644, 2645, 2914, 2915, 2916, 2986, 3594, 5798, 6104, 6206, 6228, 6402], '卡维地洛片(金络)': [158, 555, 1195, 1823, 1868, 2704, 2816, 2869, 3968, 4400, 4441, 6514], '厄贝沙坦氢氯噻嗪片(依伦平)': [21, 324, 410, 870, 1003, 1261, 1262, 1389, 1574, 1718, 1724, 1801, 1841, 2649, 2650, 2776, 2813, 2842, 2843, 3095, 3238, 3596, 3661, 3706, 3707, 3785, 3811, 3989, 4020, 4098, 4160, 4355, 4356, 4402, 4536, 4615, 4709, 4954, 4983, 4984, 5020, 5046, 5047, 5176, 5177, 5287, 5406, 5497, 5640, 5684, 5844, 5911, 5912, 5983, 6094, 6182, 6288, 6289], '厄贝沙坦氢氯噻嗪片(安博诺)': [23, 38, 65, 229, 317, 350, 384, 460, 461, 586, 632, 707, 1041, 1079, 1158, 1192, 1245, 1259, 1353, 1453, 1459, 1797, 1842, 1894, 2042, 2140, 2204, 2227, 2287, 2639, 2701, 2774, 2795, 2815, 2890, 2984, 3235, 3236, 3237, 3239, 3240, 3263, 3444, 3703, 3711, 3783, 3786, 3853, 3918, 3919, 4017, 4043, 4044, 4121, 4144, 4209, 4255, 4311, 4353, 4379, 4421, 4562, 4639, 4702, 4858, 4921, 4985, 5015, 5042, 5043, 5044, 5107, 5191, 5320, 5321, 5323, 5402, 5403, 5470, 5471, 5488, 5612, 5613, 5681, 5707, 5712, 5792, 5793, 5794, 5864, 5884, 5936, 5980, 6012, 6204, 6227, 6230, 6260, 6310, 6471, ...], '厄贝沙坦片(吉加)': [264, 269, 320, 323, 413, 465, 466, 556, 583, 795, 811, 1001, 1002, 1042, 1043, 1083, 1117, 1118, 1247, 1388, 1455, 1456, 1541, 1578, 1597, 1600, 1658, 1723, 1799, 1802, 1895, 1975, 1976, 2292, 2430, 2662, 2775, 2845, 2870, 2872, 2886, 2917, 2987, 2988, 2989, 3043, 3076, 3179, 3436, 3437, 3595, 3856, 3923, 3924, 4122, 4123, 4213, 4354, 4443, 4513, 4538, 4563, 4593, 4669, 4844, 4845, 4846, 4847, 4895, 5002, 5018, 5251, 5404, 5405, 5474, 5492, 5559, 5682, 5709, 5799, 5865, 5885, 5914, 5981, 5987, 6229, 6312, 6403, 6404, 6509, 6566, 6567, 6568], '厄贝沙坦片(安博维)': [43, 172, 195, 293, 505, 506, 576, 612, 639, 675, 825, 862, 1072, 1267, 1306, 1340, 1367, 1377, 1521, 1546, 1566, 1593, 1791, 1845, 1886, 1960, 2017, 2067, 2098, 2474, 2507, 2535, 2566, 2672, 2809, 2972, 2973, 3090, 3091, 3149, 3206, 3700, 3765, 3847, 4011, 4092, 4349, 4374, 4439, 4487, 4518, 4531, 4665, 4826, 4827, 4914, 4946, 4958, 5026, 5099, 5233, 5266, 5283, 5368, 5460, 5461, 5509, 5552, 5606, 5675, 5848, 5958, 5959, 6031, 6137, 6183, 6224, 6254, 6307, 6308, 6327, 6378, 6543, 6556, 6557], '厄贝沙坦片(科苏)': [1050, 2122, 2643, 2840, 2891, 3075, 3127, 3435, 3922, 4212, 4338, 4734, 4843, 5473, 5615, 5797, 6091, 6424], '双氢克尿塞': [255, 590, 880, 921, 962, 1665, 1736, 2233, 2237, 2354, 2758, 3107, 3163, 3496, 3795, 4049, 4427, 5078, 5298, 6315, 6316, 6329, 6449], '吲达帕胺片(寿比山)': [34, 118, 119, 216, 217, 218, 261, 272, 282, 338, 434, 435, 436, 538, 539, 572, 613, 692, 693, 740, 767, 768, 828, 829, 856, 857, 991, 1032, 1102, 1150, 1180, 1385, 1431, 1498, 1534, 1588, 1683, 1858, 1909, 2061, 2107, 2255, 2256, 2317, 2447, 2468, 2529, 2530, 2560, 2561, 2575, 2603, 2754, 2764, 2765, 2857, 2952, 2953, 3009, 3036, 3050, 3065, 3085, 3153, 3256, 3483, 3484, 3697, 3749, 3750, 3751, 3824, 3889, 3940, 4021, 4136, 4231, 4232, 4304, 4326, 4409, 4436, 4437, 4480, 4553, 4570, 4580, 4608, 4633, 4909, 4910, 4972, 4973, 5032, 5033, 5089, 5110, 5150, 5216, 5308, ...], '地巴唑片': [78, 221, 309, 444, 502, 890, 1227, 1374, 1438, 1562, 1885, 1954, 1955, 2563, 2819, 2961, 2962, 2963, 2964, 3174, 3323, 3324, 3735, 3756, 3845, 4146, 4485, 4556, 4557, 4749, 4818, 4819, 4943, 5096, 5156, 5311, 5672, 5870, 6068, 6160, 6328, 6370], '坎地沙坦酯片(必洛斯)': [83, 163, 515, 516, 713, 739, 1049, 1253, 1254, 1255, 1256, 1317, 1364, 1457, 1613, 1640, 1824, 1869, 1891, 1985, 2023, 2043, 2076, 2176, 2370, 2705, 2708, 2726, 2727, 2888, 2998, 3045, 3098, 3598, 3733, 3990, 4100, 4101, 4161, 4218, 4313, 4446, 4590, 4597, 4864, 4999, 5003, 5023, 5025, 5131, 5186, 5285, 5377, 5502, 5617, 5660, 5710, 5817, 6014, 6180, 6415, 6474], '坎地沙坦酯片(迪之雅)': [81, 156, 157, 290, 463, 633, 791, 1081, 1339, 1454, 1754, 1867, 2364, 2453, 2570, 2743, 3074, 3093, 3433, 3593, 3705, 3826, 3855, 4046, 4222, 4285, 4614, 4953, 5618, 5811, 5882, 6088, 6089, 6262, 6511, 6537, 6564, 6565], '培哚普利片(雅施达)': [634, 1000, 2454, 2722, 4442, 5128, 5616], '复方利血平氨苯蝶啶片(北京降压0号)': [12, 114, 115, 116, 117, 181, 193, 215, 280, 281, 372, 373, 388, 433, 487, 520, 537, 562, 603, 650, 670, 726, 766, 855, 887, 888, 930, 1070, 1071, 1099, 1100, 1101, 1178, 1179, 1218, 1269, 1297, 1329, 1490, 1497, 1662, 1682, 1746, 1816, 1835, 1856, 1857, 1881, 1882, 1907, 1908, 1945, 2000, 2037, 2106, 2134, 2135, 2153, 2165, 2219, 2232, 2335, 2467, 2490, 2491, 2500, 2598, 2599, 2600, 2601, 2602, 2678, 2694, 2806, 2807, 2836, 2856, 2951, 3035, 3144, 3197, 3224, 3225, 3296, 3297, 3298, 3299, 3300, 3648, 3696, 3723, 3724, 3748, 3769, 3801, 3841, 3842, 3887, 3888, 3972, ...], '复方利血平片(复方降压片)': [13, 14, 57, 76, 85, 120, 121, 122, 123, 124, 174, 219, 283, 308, 327, 340, 341, 355, 356, 374, 375, 376, 439, 440, 500, 501, 518, 540, 541, 542, 543, 544, 573, 628, 652, 653, 769, 770, 771, 830, 831, 889, 911, 931, 932, 933, 934, 935, 936, 992, 1130, 1152, 1181, 1219, 1220, 1221, 1298, 1299, 1361, 1390, 1406, 1412, 1432, 1433, 1434, 1465, 1466, 1481, 1499, 1535, 1536, 1559, 1560, 1583, 1624, 1625, 1642, 1661, 1684, 1747, 1764, 1771, 1787, 1788, 1818, 1836, 1860, 1883, 1884, 1910, 1917, 1948, 1949, 2038, 2039, 2040, 2091, 2125, 2167, 2191, ...], '复方罗布麻片': [149, 150, 151, 314, 354, 479, 579, 784, 785, 908, 973, 1051, 1243, 1399, 1446, 1447, 1448, 1502, 1570, 1705, 1752, 1866, 2075, 2115, 2196, 2341, 2368, 2393, 2630, 2631, 2632, 2707, 2771, 2777, 2867, 2910, 2978, 2979, 3003, 3047, 3130, 3267, 3427, 3447, 3448, 3449, 3911, 4227, 4835, 4836, 4837, 4838, 4957, 4980, 5012, 5065, 5221, 5286, 5787, 6083, 6084, 6109, 6324, 6391, 6542], '富马酸比索洛尔片(博苏)': [58, 125, 400, 441, 560, 858, 937, 1103, 1222, 1300, 1323, 1324, 1341, 1435, 1467, 1626, 1765, 1861, 2092, 2151, 2336, 2337, 2348, 2420, 2470, 2531, 2610, 2717, 2768, 2817, 3145, 3173, 3198, 3229, 3316, 3317, 3728, 3754, 3815, 3964, 4009, 4056, 4057, 4260, 4305, 4530, 4692, 4974, 4975, 5061, 5092, 5152, 5153, 5310, 5328, 5365, 5671, 5703, 5887, 5929, 5974, 6005, 6176, 6211, 6250, 6571], '富马酸比索洛尔片(康忻)': [55, 75, 113, 260, 371, 415, 499, 841, 929, 956, 1057, 1217, 1296, 1370, 1430, 1471, 1515, 1745, 2349, 2403, 2446, 2716, 2763, 3211, 3243, 3255, 3722, 3886, 3944, 3961, 3981, 4034, 4086, 4087, 4153, 4346, 4476, 4629, 4715, 4797, 4971, 4987, 5072, 5146, 5147, 5203, 5259, 5307, 5381, 5434, 5435, 5601, 5625, 5644, 5652, 5774, 5898, 5928, 6001, 6055, 6249, 6282, 6460], '尼群地平片': [546, 574, 615, 777, 778, 1034, 1225, 1301, 1345, 1437, 1517, 1804, 2109, 2136, 2221, 2263, 2472, 2674, 2675, 2736, 2769, 2882, 2958, 2959, 3147, 3230, 3257, 3491, 3492, 3895, 3896, 4036, 4192, 4234, 4371, 4635, 4748, 4942, 5094, 5261, 5282, 5399, 5449, 5634, 6039, 6159, 6321, 6366, 6367], '尼莫地平片': [128, 129, 130, 176, 177, 194, 220, 377, 442, 443, 575, 630, 694, 695, 727, 834, 835, 970, 1105, 1166, 1226, 1302, 1391, 1394, 1483, 1518, 1952, 1953, 2095, 2169, 2264, 2265, 2266, 2267, 2268, 2269, 2270, 2321, 2322, 2360, 2473, 2502, 2532, 2611, 2924, 2960, 3011, 3012, 3208, 3320, 3321, 3322, 3511, 3624, 3652, 3653, 3654, 3805, 4037, 4065, 4193, 4235, 4250, 4555, 4620, 4815, 4816, 4817, 4874, 5201, 5217, 5262, 5263, 5329, 5450, 5510, 5550, 5635, 5655, 6007, 6064, 6065, 6066, 6067, 6119, 6135, 6178, 6251, 6368, 6369], '开博通': [2, 3, 26, 27, 46, 50, 51, 52, 53, 89, 93, 94, 95, 96, 97, 98, 186, 187, 190, 191, 212, 237, 238, 239, 254, 256, 257, 258, 274, 276, 296, 299, 300, 301, 330, 360, 364, 391, 392, 393, 394, 420, 421, 422, 423, 490, 491, 492, 524, 525, 526, 527, 528, 529, 530, 565, 566, 567, 568, 588, 591, 592, 621, 643, 646, 680, 681, 718, 719, 720, 742, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 845, 846, 847, 878, 882, 883, 918, 922, 923, 924, 925, 961, 963, 983, 986, 987, 1009, 1010, 1011, ...], '强力VC银翘片': [0, 2521, 3953, 3996, 4068, 4112, 4266, 4452, 6273], '心痛定': [1, 49, 68, 154, 275, 363, 382, 383, 523, 897, 917, 960, 1019, 1020, 1090, 1136, 1331, 1371, 1387, 1477, 1660, 1773, 1807, 1850, 1893, 2022, 2072, 2079, 2082, 2209, 2225, 2406, 2439, 2441, 2569, 2759, 2827, 2876, 2889, 3053, 3158, 3186, 3203, 3497, 3500, 3738, 3954, 4071, 4103, 4157, 4459, 4622, 4739, 4894, 4955, 4963, 4964, 5116, 5210, 5226, 5237, 5299, 5361, 5401, 5409, 5413, 5537, 5579, 5592, 5646, 5706, 5730, 5791, 5984, 5991, 6021, 6143, 6163, 6297, 6330, 6331, 6399, 6446], '感康': [47, 188, 207, 329, 362, 467, 474, 635, 667, 879, 1015, 1060, 1199, 1200, 1249, 1271, 1277, 1338, 1476, 1503, 1504, 1604, 1618, 1619, 1663, 1830, 1896, 1926, 1988, 2126, 2182, 2326, 2351, 2438, 2494, 2518, 2522, 2576, 2646, 2663, 2684, 2822, 2825, 2826, 2927, 2928, 2929, 2930, 3021, 3137, 3162, 3266, 3272, 3274, 3275, 3793, 3833, 3861, 3925, 3932, 3973, 3997, 4025, 4026, 4070, 4124, 4224, 4258, 4268, 4455, 4456, 4457, 4501, 4522, 4652, 4653, 4676, 4718, 4719, 4762, 4763, 4764, 4765, 4848, 4849, 4903, 4930, 4990, 4991, 5005, 5024, 5068, 5173, 5174, 5475, 5531, 5536, 5538, 5683, 5743, ...], '替米沙坦片': [39, 164, 228, 1124, 1257, 1526, 1637, 1915, 2121, 2177, 2202, 2229, 2658, 2659, 3151, 3442, 4102, 4591, 4856, 5188, 5486, 5711, 6113, 6476], '替米沙坦片(立文)': [41, 386, 412, 464, 582, 676, 792, 793, 809, 810, 867, 868, 898, 947, 1194, 1246, 1315, 1347, 1380, 1460, 1638, 1711, 1712, 1713, 1973, 2174, 2198, 2289, 2290, 2291, 2308, 2309, 2367, 2642, 2703, 2744, 2912, 2913, 2985, 3126, 3434, 3920, 3921, 3931, 4018, 4211, 4223, 4336, 4500, 4534, 4566, 4567, 4640, 4860, 5017, 5127, 5171, 5172, 5373, 5472, 5490, 5491, 5582, 5583, 5938, 6090, 6103, 6144, 6290, 6400, 6401, 6423, 6512], '替米沙坦片(美卡素)': [36, 62, 287, 387, 504, 548, 995, 996, 1035, 1186, 1236, 1336, 1366, 1520, 1565, 1615, 1641, 1748, 1844, 1996, 1997, 2149, 2171, 2315, 2387, 2401, 2424, 2729, 2860, 2884, 2971, 3175, 3410, 3656, 3757, 3830, 3900, 4038, 4039, 4091, 4107, 4282, 4319, 4394, 4598, 4644, 4695, 4913, 4945, 4978, 5288, 5289, 5312, 5367, 5459, 5508, 5657, 5673, 5782, 5847, 5879, 6073, 6253, 6377, 6464, 6482, 6504, 6555], '氨加黄敏胶囊': [90, 91, 206, 1617, 1921, 4934, 5138, 5591, 5628, 5687, 5688, 5742, 6022, 6040, 6154, 6190, 6239, 6447, 6491], '氨加黄敏胶囊(请报77504)': [29, 589, 743, 981, 1016, 1017, 1089, 1202, 1272, 1494, 1739, 2007, 2686, 2781, 3106, 3135, 3864, 3948, 4129, 4269, 4458, 4602, 4961, 5077, 5415, 5662, 5686, 5689, 5716, 5826, 6488], '氨氯地平阿托伐他汀钙片(多达一)': [231, 559, 711, 786, 1039, 1162, 1265, 1450, 1706, 2487, 2488, 2772, 3261, 4015, 4283, 4318, 4397, 4495, 5556, 6469], '氯沙坦钾氢氯噻嗪片(安内喜)': [585, 824, 1756, 1827, 2231, 3078, 3734, 3827, 4220, 4407, 4510, 4511, 4704, 4855, 5378, 5586, 6148, 6416, 6510], '氯沙坦钾氢氯噻嗪片(海捷亚)': [203, 325, 343, 507, 508, 608, 894, 997, 1037, 1113, 1263, 1308, 1407, 1485, 1522, 1633, 1656, 1699, 1767, 1990, 2068, 2111, 2123, 2278, 2426, 2475, 3233, 3580, 3581, 3779, 3780, 3934, 4094, 4104, 4252, 4308, 4375, 4395, 4755, 4916, 4948, 5125, 5126, 5324, 5370, 5553, 5561, 5576, 5678, 5679, 5907, 5960, 6033, 6231, 6466, 6467], '氯沙坦钾片(缓宁)': [735, 1044, 1119, 1159, 1248, 2199, 2293, 2723, 2887, 4158, 4214, 4256, 4594, 4920, 5108, 5352, 5560, 5843, 6405, 6406], '洛丁新': [395, 493, 668, 964, 1022, 1554, 1731, 1854, 2001, 2002, 2582, 3635, 3945, 4182, 4524, 4572, 4577, 4721, 4782, 4888, 5074, 5083, 5245, 5301, 5336, 5358, 5423, 5424, 5514, 5720, 5721, 6046, 6170, 6187, 6245, 6339, 6517], '清热解毒口服液': [28, 189, 361, 390, 418, 522, 618, 666, 1492, 1829, 1925, 2028, 2081, 2208, 2234, 2235, 2236, 2325, 2405, 2440, 2493, 2520, 2550, 2551, 2682, 2732, 2757, 2801, 2926, 3052, 3157, 3214, 3495, 3716, 3792, 4069, 4148, 4168, 4169, 4170, 4267, 4291, 4359, 4451, 4453, 4454, 4523, 4542, 4651, 4761, 4901, 4902, 4931, 4932, 4933, 5075, 5076, 5115, 5136, 5240, 5414, 5565, 5741, 5851, 5890, 5921, 5943, 5944, 6236, 6237, 6444, 6445, 6545], '珍菊降压片': [24, 56, 173, 245, 294, 339, 399, 437, 438, 627, 651, 877, 1151, 1602, 1817, 1859, 1946, 1947, 1998, 2062, 2108, 2166, 2220, 2257, 2318, 2319, 2418, 2501, 2604, 2673, 2858, 2859, 2880, 2954, 3086, 3087, 3207, 3301, 3302, 3303, 3304, 3305, 3649, 3774, 3857, 3962, 4190, 4233, 4393, 4438, 4481, 4529, 4802, 4803, 4804, 4868, 4926, 5260, 5326, 5344, 5380, 5441, 5442, 5523, 6157, 6174, 6198, 6199, 6200, 6283, 6483], '盐酸咪达普利片(达爽)': [701, 728, 1110, 1863, 2110, 2548, 3183, 4062, 4696, 5314, 5933, 6016], '盐酸普萘洛尔片(心得安)': [40, 171, 202, 250, 251, 292, 473, 512, 610, 677, 806, 903, 904, 952, 1006, 1411, 1543, 1725, 1770, 1870, 1987, 2024, 2074, 2077, 2489, 2512, 2797, 3265, 3812, 4106, 4143, 4286, 4314, 4512, 4896, 5000, 5189, 5408, 5733, 5967, 6101, 6102, 6265, 6291, 6326, 6418], '盐酸特拉唑嗪片(马沙尼)': [452, 1155, 1337, 1444, 1700, 2193, 3412, 3759, 3849, 4162, 4440, 4610, 4750, 5036, 5462, 5908, 6541], '硝苯地平控释片(欣然)': [18, 347, 348, 510, 865, 909, 974, 1449, 1544, 1635, 1874, 1970, 2117, 2452, 2633, 2634, 2667, 3101, 3123, 3451, 3761, 3809, 3851, 3967, 4381, 4839, 4917, 5197, 5250, 5269, 5270, 5319, 5354, 5468, 5496, 5841, 6258, 6309, 6393], '硝苯地平片(心痛定)': [17, 42, 84, 139, 140, 141, 142, 143, 144, 145, 146, 147, 165, 166, 197, 198, 204, 222, 223, 344, 345, 378, 379, 408, 453, 454, 455, 456, 475, 476, 477, 478, 509, 514, 550, 551, 577, 587, 637, 655, 656, 702, 703, 710, 781, 782, 783, 814, 815, 863, 864, 875, 895, 896, 906, 907, 944, 945, 971, 977, 998, 1007, 1074, 1075, 1076, 1087, 1114, 1115, 1161, 1239, 1240, 1241, 1264, 1309, 1310, 1318, 1319, 1320, 1348, 1351, 1352, 1395, 1398, 1408, 1409, 1445, 1461, 1486, 1487, 1501, 1569, 1579, 1580, 1594, 1595, 1601, 1701, 1702, 1703, 1749, ...], '缬沙坦分散片(易达乐)': [19, 167, 199, 657, 731, 732, 1657, 1839, 2567, 2573, 2635, 2636, 2981, 3763, 4206, 4317, 4595, 4708, 5013, 5272, 5371, 5526, 5638, 5639, 5729, 5815, 5842, 6085, 6179, 6394, 6395], '缬沙坦氢氯噻嗪片(复代文)': [3128, 5708], '缬沙坦氨氯地平片(I)(倍博特)': [160, 351, 352, 812, 813, 1120, 1316, 1488, 1573, 1717, 1755, 1769, 1914, 2343, 2648, 2724, 2841, 3730, 3926, 3933, 4047, 4444, 4568, 4641, 4861, 5175, 5375, 5476, 5642, 5802, 5965, 6093, 6105], '缬沙坦胶囊(代文)': [31, 104, 184, 213, 242, 243, 333, 396, 496, 533, 624, 649, 686, 687, 723, 724, 759, 760, 761, 851, 884, 959, 966, 967, 1026, 1059, 1094, 1095, 1132, 1146, 1173, 1174, 1175, 1288, 1289, 1290, 1291, 1325, 1326, 1368, 1369, 1373, 1423, 1424, 1425, 1623, 1652, 1653, 1674, 1675, 1741, 1758, 1828, 2035, 2056, 2087, 2104, 2164, 2206, 2247, 2414, 2415, 2459, 2465, 2558, 2590, 2591, 2592, 2714, 2820, 2943, 3013, 3133, 3155, 3167, 3223, 3251, 3252, 3253, 3289, 3493, 3625, 3636, 3680, 3798, 3821, 3859, 3971, 3993, 4005, 4006, 4022, 4033, 4052, 4080, 4081, 4115, 4116, 4261, 4276, ...], '苯磺酸左旋氨氯地平片(施慧达)': [80, 138, 196, 247, 288, 407, 517, 549, 714, 729, 730, 826, 827, 943, 1036, 1073, 1111, 1112, 1237, 1238, 1307, 1321, 1322, 1567, 1568, 1632, 1728, 1876, 1877, 2018, 2044, 2150, 2172, 2223, 2224, 2277, 2316, 2361, 2388, 2720, 2770, 2838, 2907, 2908, 3049, 3120, 3150, 3200, 3231, 3232, 3270, 3411, 3482, 3758, 3807, 3848, 3901, 3902, 4093, 4141, 4164, 4200, 4307, 4350, 4586, 4587, 4619, 4697, 4731, 4893, 4915, 4947, 4959, 4979, 4997, 5035, 5053, 5063, 5100, 5101, 5133, 5160, 5234, 5284, 5290, 5291, 5315, 5316, 5346, 5369, 5607, 5621, 5643, 5676, 5677, 5704, 5727, 5735, 5736, 5785, ...], '苯磺酸氨氯地平片(兰迪)': [1311, 5109, 5788], '苯磺酸氨氯地平片(安内真)': [16, 35, 60, 61, 66, 82, 86, 131, 132, 133, 134, 135, 136, 137, 161, 162, 168, 169, 201, 233, 234, 249, 262, 263, 265, 266, 267, 268, 270, 271, 286, 321, 326, 401, 402, 403, 404, 405, 406, 445, 446, 447, 448, 449, 450, 451, 468, 469, 470, 471, 472, 481, 482, 503, 519, 547, 557, 561, 604, 605, 606, 607, 616, 631, 641, 654, 659, 660, 661, 662, 663, 671, 672, 673, 674, 697, 698, 699, 700, 736, 737, 779, 780, 796, 797, 798, 799, 800, 801, 802, 803, 804, 819, 820, 821, 822, 823, 860, 871, 872, ...], '苯磺酸氨氯地平片(络活喜)': [4, 5, 6, 25, 70, 71, 88, 99, 100, 182, 183, 253, 277, 302, 303, 304, 331, 357, 358, 365, 416, 488, 489, 494, 521, 563, 593, 594, 595, 617, 622, 642, 669, 682, 683, 684, 721, 722, 741, 756, 757, 758, 842, 849, 957, 958, 988, 1008, 1023, 1064, 1093, 1134, 1135, 1142, 1143, 1198, 1208, 1209, 1270, 1330, 1357, 1381, 1384, 1401, 1402, 1419, 1420, 1421, 1472, 1479, 1495, 1507, 1508, 1509, 1527, 1528, 1555, 1584, 1616, 1621, 1622, 1648, 1670, 1671, 1732, 1733, 1734, 1760, 1780, 1781, 1806, 1847, 1901, 1902, 1920, 1937, 1938, 2011, 2032, 2033, ...], '赖诺普利片(信赖安)': [2397, 4981, 6145], '酒石酸美托洛尔片(倍他乐克)': [9, 10, 11, 32, 33, 44, 54, 74, 87, 105, 106, 107, 108, 109, 110, 111, 112, 178, 179, 180, 192, 205, 214, 244, 252, 278, 279, 295, 307, 328, 334, 335, 336, 337, 367, 368, 369, 370, 397, 398, 427, 428, 429, 430, 431, 432, 483, 484, 485, 486, 497, 498, 534, 535, 536, 570, 571, 599, 600, 601, 602, 625, 626, 664, 688, 689, 690, 691, 725, 762, 763, 764, 765, 836, 837, 838, 839, 840, 852, 853, 854, 885, 886, 913, 914, 927, 928, 955, 968, 969, 989, 990, 1027, 1028, 1029, 1030, 1031, 1054, 1055, 1056, ...], '醒脑降压丸': [185, 208, 273, 1201, 1927, 2683, 4766, 6490], '阿司匹林': [45, 48, 67, 210, 715, 844, 920, 982, 1018, 1278, 1354, 1382, 1548, 1549, 1646, 1664, 1735, 1831, 1898, 2029, 2352, 2353, 2461, 2552, 2553, 2710, 2733, 3079, 3718, 3737, 3794, 3949, 3998, 4027, 4048, 4130, 4543, 4575, 4767, 4768, 4904, 4905, 4962, 5027, 5056, 5139, 5241, 5359, 5360, 5383, 5517, 5566, 5664, 5717, 5718, 5744, 5745, 5873, 5942, 5945, 5992, 6042, 6240, 6448], '雷米普利片(瑞素坦)': [8, 389, 426, 569, 843, 1025, 1210, 1359, 1673, 1815, 1941, 2180, 2246, 2373, 2437, 2589, 2788, 3060, 4434, 4521, 5215, 6522], '非洛地平缓释片(康宝得维)': [72, 101, 332, 495, 596, 647, 678, 926, 1144, 1167, 1168, 1422, 1649, 1650, 1672, 2131, 2162, 2163, 2357, 2832, 2875, 2878, 3059, 3744, 3959, 4003, 4023, 4273, 4345, 4365, 4415, 4466, 4722, 5010, 5122, 5627, 5693, 5769, 6153, 6193, 6276, 6277], '非洛地平缓释片(波依定)': [7, 30, 73, 102, 235, 240, 241, 259, 305, 306, 424, 425, 531, 532, 564, 597, 623, 648, 685, 850, 915, 1024, 1058, 1065, 1066, 1067, 1145, 1172, 1282, 1283, 1284, 1285, 1286, 1333, 1491, 1510, 1511, 1585, 1651, 1761, 1762, 1782, 1783, 1814, 1879, 1903, 1939, 2003, 2012, 2055, 2086, 2161, 2245, 2436, 2444, 2525, 2526, 2557, 2681, 2691, 2713, 2787, 2821, 2849, 2850, 3017, 3028, 3082, 3139, 3185, 3212, 3222, 3249, 3250, 3286, 3287, 3288, 3507, 3628, 3679, 3715, 3720, 3790, 3836, 3878, 3879, 4004, 4079, 4274, 4275, 4290, 4298, 4324, 4342, 4366, 4367, 4391, 4464, 4465, 4526, ...], '马来酸依那普利片(怡那林)': [209, 359, 919, 2685, 3051, 3215, 3834, 4246, 4412, 5006, 5590, 6519], '马来酸左旋氨氯地平片(玄宁)': [22, 37, 155, 1040, 1191, 1710, 1796, 1840, 2203, 2226, 2400, 3262, 3852, 4405, 4952, 4998, 5190, 5220, 5374, 5580, 5641, 5659, 5731, 5913, 6422], '高特灵': [69, 92, 211, 236, 298, 419, 644, 645, 679, 716, 717, 744, 745, 848, 881, 984, 985, 1045, 1137, 1170, 1203, 1204, 1349, 1414, 1505, 1550, 1586, 1607, 1620, 1666, 1667, 1774, 1809, 1878, 1899, 1900, 1928, 1929, 2101, 2127, 2142, 2211, 2331, 2374, 2577, 2828, 2877, 2896, 3054, 3055, 3164, 3187, 3276, 3501, 3502, 3630, 3631, 3675, 3717, 3739, 3740, 3741, 3791, 3816, 3862, 3863, 3865, 3866, 3867, 3950, 3951, 3952, 3955, 3974, 3975, 3976, 3977, 3994, 3995, 4111, 4131, 4149, 4159, 4171, 4172, 4173, 4174, 4292, 4343, 4428, 4541, 4677, 4717, 4740, 4769, 4883, 4884, 4935, 5055, 5079, ...]}"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.groupby('商品名称').groups"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
